<?php
// 指定允许其他域名访问  
header('Access-Control-Allow-Origin:*');  
// 响应类型  
header('Access-Control-Allow-Methods:POST');  
// 响应头设置  
header('Access-Control-Allow-Headers:x-requested-with,content-type');  

if (isset($_FILES["file"]) || !is_uploaded_file($_FILES["file"]["tmp_name"]) || $_FILES["file"]["error"] != 0) {
    $upload_file = $_FILES['file'];
    $file_info   = pathinfo($upload_file['name']);
    $file_type   = $file_info['extension'];

    $upload_dir  =  "pic/".date('Y/md/'); 

    if(!file_exists($upload_dir)){  
        mkdir($upload_dir,0777,true);  
    }  

    $destination  = $upload_dir.md5(uniqid($_FILES["file"]['name'])) . '.' . $file_info['extension'];
    //$destination        = '../images/' . $_FILES["file"]['name'];
    $filename  = $_FILES['file']['tmp_name'];

    if (!move_uploaded_file($filename, $destination)) {
        exit;
    }

    echo $destination;

    //将数组的输出存起来以供查看
    $text = 'test.txt';
    $postData = var_export($file_info, true);

    file_put_contents($text, $postData);

    // $file     = fopen('' . $fileName, "w");
    // fwrite($file,$postData);
    // fclose($file);
}

?>